package com.hxzy.springbootrocketproducer.controller;

import com.hxzy.springbootrocketproducer.dto.User;
import com.hxzy.springbootrocketproducer.service.ProducerService;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendController {

    @Autowired
    private ProducerService  producerService;

    /**
     * 发送普通消息
     * @param user
     * @return
     */
    @GetMapping(value = "/send/user")
    public String sendUser(User user){
      this.producerService.sendMessage(user);

      return "OK";
    }


    /**
     * 发送同步消息
     * @param msgBody
     * @return
     */
    @GetMapping(value = "/send/sync")
    public SendResult sendMsg(String msgBody){
        return this.producerService.sendMsg(msgBody);
    }

    /**
     * 发送异步消息
     * @param msgBody
     */
    @GetMapping(value = "/send/async")
    public String sendAsyncMsg(String msgBody){
        this.producerService.sendAsyncMsg(msgBody);
        return "异步消息发送成功";
    }


    /**
     * 发送延迟消息
     * @param msgBody
     * @param delayLevel 1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
     * @return
     */
    @GetMapping(value = "/send/delay")
    public String sendDelayMsg(String msgBody, int delayLevel){
        this.producerService.sendDelayMsg(msgBody,delayLevel);
        return "发送延迟消息";
    }

    /**
     * 发送单向消息（不关心发送结果，如日志）
     */
    @GetMapping(value = "/send/one")
    public String sendOneWayMsg(String msgBody){
        this.producerService.sendOneWayMsg(msgBody);
        return "发送单向消息";
    }



}
